/**   
* @Title: ServerHandler.java
* @Package com.an.md5str
* @Description: TODO(用一句话描述该文件做什么)
* @author antch,861710865@qq.com   
* @date 2017年8月1日 下午4:53:24
* @version V1.0   
*/


package com.an.md5str;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
* @ClassName: ServerHandler
* @Description: TODO(这里用一句话描述这个类的作用)
* @author antch,861710865@qq.com
* @date 2017年8月1日 下午4:53:24
* 
*/

public class ServerHandler extends SimpleChannelInboundHandler<String> {

	/* (非 Javadoc) 
	* <p>Title: handlerAdded</p> 
	* <p>Description: </p> 
	* @param ctx
	* @throws Exception 
	* @see io.netty.channel.ChannelHandler#handlerAdded(io.netty.channel.ChannelHandlerContext) 
	*/

	@Override
	public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
		// TODO Auto-generated method stub

	}

	/* (非 Javadoc) 
	* <p>Title: handlerRemoved</p> 
	* <p>Description: </p> 
	* @param ctx
	* @throws Exception 
	* @see io.netty.channel.ChannelHandler#handlerRemoved(io.netty.channel.ChannelHandlerContext) 
	*/

	@Override
	public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
		// TODO Auto-generated method stub

	}

	/* (非 Javadoc) 
	* <p>Title: exceptionCaught</p> 
	* <p>Description: </p> 
	* @param ctx
	* @param cause
	* @throws Exception
	* @deprecated 
	* @see io.netty.channel.ChannelHandler#exceptionCaught(io.netty.channel.ChannelHandlerContext, java.lang.Throwable) 
	*/

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
		// TODO Auto-generated method stub
		/*System.out.println("from client:" + message);  
        JSONObject json = JSONObject.fromObject(message);  
        String source = json.getString("source");  
  
        String md5 = DigestUtils.md5Hex(source);  
        //解析成JSON  
        json.put("md5Hex",md5);  
        ctx.writeAndFlush(json.toString());//write bytes to socket,and flush(clear) the buffer cache.  
   */ }  
  
    @Override  
    public void channelReadComplete(ChannelHandlerContext ctx) {  
        ctx.flush();  
    }  
  
	

}
